from pymongo import MongoClient  

# 替换为实际配置  
USER = "admin"  
PWD = "123456"  
HOST = "116.62.50.24"  
PORT = 27017  

try:  
    client = MongoClient(f"mongodb://{USER}:{PWD}@{HOST}:{PORT}/admin?authSource=admin", serverSelectionTimeoutMS=5000)  
    client.admin.command("ismaster")  # 测试连接  
    print("✅ MongoDB 连接成功！")  

    # 测试数据读写（可选）  
    db = client.test  
    db.col.insert_one({"hello": "mongo"})  
    print("插入数据：", db.col.find_one())  

except Exception as e:  
    print(f"❌ 失败：{e}")
